﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Calculator_Win
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void NumBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8 && e.KeyChar != '.' && e.KeyChar != '-')
                e.Handled = true;
        }

        private void NumBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8 && e.KeyChar != '.' && e.KeyChar != '-')
                e.Handled = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(NumBox1.Text == "" || NumBox2.Text == "" || NumBox1.Text == "." || NumBox2.Text == "." || NumBox1.Text == "-" || NumBox2.Text == "-")
                return;
            double num1 = Convert.ToDouble(NumBox1.Text);
            double num2 = Convert.ToDouble(NumBox2.Text);
            string s = symbol.Text;
            switch (s)
            {
                case "+":ResBox.Text = (num1+num2).ToString(); break;
                case "-":ResBox.Text = (num1-num2).ToString(); break;
                case "*":ResBox.Text = (num1*num2).ToString(); break;
                case "/":
                    if (num2 == 0)
                        ResBox.Text = "除数不能为0！";
                    else
                        ResBox.Text = (num1 / num2).ToString();
                    break;
                default:break;
            }
        }


    }
}
